package com.example.microinvestweb.controller.stock;
import com.example.microinvestcommon.pojo.Result;
import com.example.microinvestcommon.vo.StockNumSymbolVo;
import com.example.microinvestmarket.service.InitializeService;
import com.example.microinvestmarket.service.StockCountService;
import com.example.microinvestmarket.service.StockDataGetService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/stock")
public class StockController {

    private final StockCountService stockCountService;

    private final InitializeService initializeService;

    private final StockDataGetService stockDataGetService;

    private static final Logger logger = LoggerFactory.getLogger(StockController.class);

    @Autowired
    public StockController(StockCountService stockCountService,InitializeService initializeService,StockDataGetService stockDataGetService){
        this.stockCountService=stockCountService;
        this.initializeService=initializeService;
        this.stockDataGetService=stockDataGetService;
    }

    @GetMapping("/getStockMessage")
    public Result<List<Double>> getStocksMessage(@RequestParam(value = "stockName") String stockName, @RequestParam(value = "key") int key) throws Exception {
        Result<List<Double>> result= stockCountService.getStockMessage(stockName,key);
        return result;
    }

//
//    @PostMapping("/createStockData")
//    public Result createStock(String StockName, double FirstPrice) throws Exception{
//        Result<List<String>> result=stockCountService.createStock(StockName,FirstPrice);
//        return result;
//    }

////     定时任务：每天00:00执行一次
//    @Scheduled(cron="0/2 * *  * * ? ")  // 每天的 0 点执行 0 0 0/秒分时 **/每月每一天和每周每一天执行 ？表示不指定特定星期
//    public void autoCreateStockData() throws Exception {
//        stockCountService.createStock();
//    }

    @PostMapping("/initializeStockMessage")
    public Result initializeStockMessage(Integer initializeStockNum){
        Result result=initializeService.batchInsertStockData(initializeStockNum);
        return result;
    }

    //获取所有stock的Symbol
    @GetMapping("/getStockSymbol")
    public Result<List<String>> getAllStockSymbol(){
        Result result=stockDataGetService.getAllStockName();
        return result;
    }

    @GetMapping("/getStockNumAndSymbol")
    public Result<List<StockNumSymbolVo>> getAllStocksNumAndSymbol(){
        Result result=stockDataGetService.getAllStocksNumAndSymbol();
        return result;
    }

    //获取一只股票的15mink图
    @GetMapping("/getOneFiveDataWithStockSymbol")
    public Result<List<Double>> getStockOneFiveData(String stockSymbol){
        Result result=stockDataGetService.getStockOneFiveMinData(stockSymbol);
        return result;
    }

}

